#include "apue.h"
#include "error.c"
#include <fcntl.h>
#include <unistd.h>

#define MAX_BUFF 4096

/**
 * 
 */
int main(int argc, char *argv[])
{
    if(argc != 2)
        err_quit("param error");

    int rd_fd;

    char buffer[MAX_BUFF];
    ssize_t n;
    if((rd_fd = open(argv[1], O_RDWR | O_CREAT, 0644)) == -1){
        err_sys("file open error");
    }

    // unsigned long long value = 0x100;
    // if((n = write(rd_fd, &value, sizeof(value))) == -1){
    //     err_sys("write value error");
    // }


    // if((n = read(STDIN_FILENO, buffer, MAX_BUFF)) == -1){
    //     err_sys("read data error, STDIN_FILENO");
    // }


    // if(lseek(rd_fd, 16348*1024, SEEK_CUR) == -1){
    //     err_sys("lseek set file off_set 16384 error");
    // }
    if(lseek(rd_fd, 16384, SEEK_SET) == -1)
        err_sys("lseek error");
    
    
    // if((n = write(rd_fd, buffer, n)) == -1){
    //     err_sys("write value error");
    // }

    // lseek(rd_fd, 0, SEEK_SET);
    // while((n = read(rd_fd, buffer, MAX_BUFF))){
    //     if(write(STDOUT_FILENO, buffer, n)){
    //          err_sys("write STDOUT_FILENO error");
    //     }
    // }
    unsigned long long value = 0x100;
    if((n = write(rd_fd, &value, sizeof(value))) == -1){
        err_sys("write value error");
    }
    close(rd_fd);
    return 0;
}
